package indi.zhifa.recipe.bailan5.coupon.handler;

import com.alibaba.fastjson2.JSON;
import indi.zhifa.recipe.bailan.framework.queue.handler.IMessageHandler;
import indi.zhifa.recipe.bailan5.coupon.dao.service.ICouponDbService;
import indi.zhifa.recipe.bailan5.coupon.entity.po.CouponEntity;
import indi.zhifa.recipe.bailan5.coupon.entity.po.msg.CouponStorageMsg;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@RequiredArgsConstructor
@Component
public class CouponMsgHandler implements IMessageHandler<CouponStorageMsg> {

    private final ICouponDbService mCouponDbService;
    @Override
    public void handler(CouponStorageMsg message) {
        log.info("接到消息，"+ JSON.toJSONString(message));
        CouponEntity couponEntity = new CouponEntity();
        couponEntity.setId(message.getId());
        couponEntity.setStorage(message.getStorage());
        mCouponDbService.updateById(couponEntity);
    }

}
